package com.deng.controller;

import com.deng.Service.CommentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMethod;
import java.util.Map;

/**
 * @Author 邓小熙
 * @Date 2022/5/13 9:55
 * @Version 1.0
 */
@Controller
public class CommentsController {
    @Autowired
    CommentsService commentsService;
    /**
     * 主页的评论信息 不需要权限控制 而上面的需要权限控制 和request.post控制
     * @return
     */
    @RequestMapping (value = "/main/comments/commentsWithPaperAndUserMes",method = RequestMethod.POST)
    public @ResponseBody
    Map<String,Object> commentsWithPaperAndUserMes(){
        return commentsService.findAllCommentsOrderByTime();
    }
    /**
     * 通过文章ID查找所有相应文章的评论
     * @param id
     * @return
     */
    @RequestMapping(value = "/comments/ByPaperId/{id}")
    public @ResponseBody Map<String,Object> commentsByPaperId(@PathVariable("id") int id){
        return commentsService.findAllCommentsByPaperId(id);
    }

    /**
     * 个人主页的评论动态
     * @param userName
     * @return
     */
    @RequestMapping(value ={"pageStat","/main/comments/PersonalComments"} )
    public @ResponseBody Map<String,Object> PersonalComments(@RequestParam("userName") String userName){
        return commentsService.findCommentsByUserId(userName);
    }

    /**
     * 增加评论
     * @param userName
     * @param pageId
     * @param text
     * @return
     */
    @RequestMapping(value = "/main/comments/insertComment")
    public @ResponseBody int insertComment(@RequestParam("userName") String userName,@RequestParam("pageId") int pageId,@RequestParam("text") String text){
        return commentsService.insertComments(text,pageId,userName);
    }

    /**
     * 后台文章管理中的评论操作
     * @return
     */
    @RequestMapping( value = "/comments/getComments")
    public String getComments(){
        return "InnerLayui/caozuo/comMes";
    }

    @RequestMapping(value = "/comments/deleteComment/{id}")
    public @ResponseBody int deleteComment(@PathVariable("id") int id){
        return commentsService.deleteCommentById(id);
    }


//    @RequestMapping(value = "/main/comments/PersonalComments")
//    public @ResponseBody Map<String,Object> PersonalComments(@RequestParam("userName") String userName){
//        return commentsService.findCommentsByUserId(userName);
//    }
}
